package com.hbnu.system.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.hbnu.system.core.base.CommonPage;
import com.hbnu.system.core.base.Rest;
import com.hbnu.system.model.dto.CheckBackDTO;
import com.hbnu.system.model.dto.ReportAddDTO;
import com.hbnu.system.model.dto.SearchPageDTO;
import com.hbnu.system.model.dto.UserDTO;
import com.hbnu.system.model.entity.Report;
import com.hbnu.system.service.IReportService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ${author}
 * @since 2023-05-16
 */
@RestController
@RequestMapping("/report")
@Api(tags = "报告模块")
public class ReportController {
    @Autowired
    IReportService iReportService;

    @ApiOperation("报告-正式录入")
    @PostMapping("/addReport")
    public Rest<Boolean> AddReport(@RequestBody Report report){
        boolean add = iReportService.addReport(report);
        return add ? Rest.success() : Rest.failed();
    }

    @ApiOperation("报告-初次录入")
    @PostMapping("/addreportDTO")
    public Rest<Boolean> Addreport(@RequestBody ReportAddDTO reportAddDTO){
        boolean add = iReportService.addReport(reportAddDTO);
        return add ? Rest.success() : Rest.failed();
    }

    @ApiOperation("报告-删除")
    @GetMapping("/Deletereport")
    public Rest<Boolean> DeleteReport(String ID){
        boolean delete = iReportService.deleteReport(ID);
        return delete ? Rest.success() : Rest.failed();
    }

    @ApiOperation("报告-提交")
    @GetMapping("/ReCommitReport")
    public Rest<Boolean> ReCommitReport(String ID){
        boolean add = iReportService.ReCommitReport(ID);
        return add ? Rest.success() : Rest.failed();
    }
    
    @ApiOperation("报告-撤回")
    @GetMapping("/WithdrawReport")
    public Rest<Boolean> WithdrawReport(String ID){
        boolean add = iReportService.withdrawReport(ID);
        return add ? Rest.success() : Rest.failed();
    }


    @ApiOperation("报告-名称查重")
    @GetMapping("/CheckReportName")
    public Rest<Boolean> CheckReportName(String name){
        boolean check = iReportService.checkReportName(name);
        return check ? Rest.success() : Rest.failed();
    }

    @ApiOperation("根据主键报告查询")
    @GetMapping("/GetReportById")
    public Rest<Report> GetReportById(String ID){
        Report report = iReportService.getReport(ID);
        return Rest.success(report);
    }

    @ApiOperation("报告-分页查询")
    @PostMapping ("/pagecondition")
    public Rest<CommonPage<Report>> pageProjectCondition(@RequestBody SearchPageDTO searchTaskDTO){
        IPage<Report> page = iReportService.pageCondition(searchTaskDTO);
        CommonPage<Report> activityVOCommonPage = CommonPage.restPage(page);
        return Rest.success(activityVOCommonPage);
    }

    @ApiOperation("报告-院级通过")
    @GetMapping("/CollegeCheckPass")
    public Rest<String> CollegePassreport(@RequestHeader("X-Token") String token,String PID){
        Boolean b = iReportService.collegeCheckPass(token,PID);
        return b ? Rest.success() : Rest.failed();
    }

    @ApiOperation("报告-院级退回")
    @PostMapping("/CollegeCheckBack")
    public Rest<String> CollegeBackReport(@RequestHeader("X-Token") String token,@RequestBody CheckBackDTO checkBackDTO){
        Boolean b = iReportService.collegeCheckBack(token,checkBackDTO);
        return b ? Rest.success() : Rest.failed();
    }

    @ApiOperation("报告-校级通过")
    @GetMapping("/SchoolCheckPass")
    public Rest<String> SchoolPassReport(@RequestHeader("X-Token") String token,String PID){
        Boolean b = iReportService.schoolCheckPass(token,PID);
        return b ? Rest.success() : Rest.failed();
    }

    @ApiOperation("报告-校级退回")
    @PostMapping("/SchoolCheckBack")
    public Rest<String> SchoolBackReport(@RequestHeader("X-Token") String token,@RequestBody CheckBackDTO checkBackDTO){
        Boolean b = iReportService.schoolCheckBack(token,checkBackDTO);
        return b ? Rest.success() : Rest.failed();
    }

    @ApiOperation("用户获取与自己相关的报告-分页")
    @PostMapping("/UserGetRelateReport")
    public Rest<CommonPage<Report>> UserGetRelatereport(@RequestBody UserDTO userDTO){
        IPage<Report> reportIPage = iReportService.userGetRelateReport(userDTO);
        CommonPage<Report> paperVOCommonPage = CommonPage.restPage(reportIPage);
        paperVOCommonPage.setFigure(iReportService.getFigure(userDTO)[0]);
        return Rest.success(paperVOCommonPage);
    }

    @ApiOperation("院级管理员查看需要自己审核的报告-分页")
    @PostMapping("/CollegeUserGetReport")
    public Rest<CommonPage<Report>> CollegeUserGetreport(@RequestBody UserDTO userDTO){
        IPage<Report> reportIPage = iReportService.collegeUserGetReport(userDTO);
        CommonPage<Report> paperCommonPage = CommonPage.restPage(reportIPage);
        return Rest.success(paperCommonPage);
    }

    @ApiOperation("校级管理员查看需要自己审核的报告-分页")
    @PostMapping("/SchoolUserGetReport")
    public Rest<CommonPage<Report>> SchoolUserGetreport(@RequestBody UserDTO userDTO){
        IPage<Report> reportIPage = iReportService.schoolUserGetReport(userDTO);
        CommonPage<Report> paperCommonPage = CommonPage.restPage(reportIPage);
        return Rest.success(paperCommonPage);
    }
}

